﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Forms;
using AndyPike.Experiments.MEF.Contracts;

namespace AndyPike.Experiments.MEF
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [Import]
        public IEnumerable<ITextFormatter> TextFormatters { get; set; }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            foreach (var textFormmater in TextFormatters)
            {
                formatters.Items.Add(textFormmater);
            }
        }

        private void formatters_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            var formatter = (ITextFormatter)formatters.SelectedItem;
            text.Text = formatter.Format(text.Text);
        }
    }
}
